/**
 *
 * ......................我佛慈悲.......................
 *                       _oo0oo_
 *                      o8888888o
 *                      88" . "88
 *                      (| -_- |)
 *                      0\  =  /0
 *                    ___/`---'\___
 *                  .' \\|     |// '.
 *                 / \\|||  :  |||// \
 *                / _||||| -卍-|||||- \
 *               |   | \\\  -  /// |   |
 *               | \_|  ''\---/''  |_/ |
 *               \  .-\__  '-'  ___/-. /
 *             ___'. .'  /--.--\  `. .'___
 *          ."" '<  `.___\_<|>_/___.' >' "".
 *         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
 *         \  \ `_.   \_ __\ /__ _/   .-` /  /
 *     =====`-.____`.___ \_____/___.-`___.-'=====
 *                       `=---='
 *
 *..................佛祖开光 ,永无BUG....................
 *         CSDN博客:http://blog.csdn.net/song5347
 *       github地址:https://github.com/lingsuiderongyan
 *             邮箱:lingsuiderongyan@163.com
 */

import UIKit
//微博toolbar
class LSStatusToolBar: UIView {
    
    //转发按钮
    var retweetButton: UIButton?
    //评论按钮
    var commentButton: UIButton?
    //赞按钮
    var unlikeButton: UIButton?
    
    var statusViewModel: LSStatusViewModel? {
        didSet {
//            let retweetCount = statusViewModel?.status?.reposts_count ?? 0
//            let commentCount = statusViewModel?.status?.comments_count ?? 0
//            let unlikeCount = statusViewModel?.status?.attitudes_count ?? 0
//            
//            retweetButton?.setTitle("\(retweetCount)", forState: .Normal)
//            commentButton?.setTitle("\(commentCount)", forState: .Normal)
//            unlikeButton?.setTitle("\(unlikeCount)", forState: .Normal)
            //
            retweetButton?.setTitle(statusViewModel?.retweetCountContent, forState: .Normal)
            commentButton?.setTitle(statusViewModel?.commentCountContent, forState: .Normal)
            unlikeButton?.setTitle(statusViewModel?.unlikeCountContent, forState: .Normal)
        }
    }

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK: - 添加控件约束
    private func setupUI() {
        //添加按钮
        retweetButton = addChildButton("timeline_icon_retweet", title: "转发")
        commentButton = addChildButton("timeline_icon_comment", title: "评论")
        unlikeButton = addChildButton("timeline_icon_unlike", title: "赞")
        
        //添加竖线
        let firstLineView  = addChildLineView()
        let secondLineView = addChildLineView()
        
        //约束
        retweetButton!.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentButton!)
        }
        
        commentButton!.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton!.snp_trailing)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(unlikeButton!)
        }
        
        unlikeButton!.snp_makeConstraints { (make) -> Void in
            make.trailing.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.leading.equalTo(commentButton!.snp_trailing) //.offset(0) //修复竖线不显示
        }
        
        firstLineView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetButton!.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        secondLineView.snp_makeConstraints { (make) -> Void in
            make.centerY.equalTo(self)
            make.centerX.equalTo(commentButton!.snp_trailing)
        }
    }
    
    //MARK: - 添加子按钮的通用方法
    private func addChildButton(imageName: String, title: String) -> UIButton {
        
        let button = UIButton()
        
        //设置图片
        button.setImage(UIImage(named: imageName), forState: .Normal)
        //设置背景图片
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        //设置文字与颜色
        button.setTitle(title, forState: .Normal)
        button.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        
        //设置字体
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        addSubview(button)
        return button
    }
    
    //MARK: - 添加子竖线的通用方法
    private func addChildLineView() -> UIImageView {
        
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imageView)
        return imageView
    }

}






















